import { _decorator, Animation, AnimationState, Collider2D, Component, Contact2DType, IPhysics2DContact, Node, PhysicsSystem2D } from 'cc';
import { Direction, MoveBaseEntity, Role } from './MoveBaseEntity';
import { GameScene } from './GameScene';
const { ccclass, property } = _decorator;

/**
 * 敌机
 */
@ccclass('Enemy')
export class Enemy extends MoveBaseEntity {
    /**
     * 被击落添加的分数
     */
    @property
    score:number = 100;

    update(dt: number) {
        const p = this.node.getPosition().clone();
        p.y -= dt * this.speed;
        this.node.setPosition(p);

        super.update(dt);
    }

    protected onDestroy(): void {
        super.onDestroy();

        GameScene.inst.removeEnemy(this.node);
    }

    dead(dt: number): boolean {
        const flag = super.dead(dt);
        if(flag) {
            GameScene.inst.addScore(this.score);
        }
        
        return flag;
    }

    killNow() {
        const dt = this._injured(this.hp);
        const flag = this.dead(dt);
        return flag;
    }
}

